<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2018 http://www.donglixia.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: 十万马 <962863675@qq.com>
// +----------------------------------------------------------------------
// | DateTime: 2018-02-09 16:17
// +----------------------------------------------------------------------

namespace app\tradi\controller;

use app\index\model\Article;
use think\Request;

class News extends Base
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->currentModel = new Article();//实例化当前模型
    }

    /**
     * 信息中心
     * @return mixed
     */
    public function index()
    {
        //获取数据列表
        $param = $this->request->param();
        $cat_id = !empty($param['cat_id']) ? $param['cat_id'] : 56;

        $cat_ids = get_child_ids($cat_id, 'article_cat');//获取子分类cat_id
        $map['cat_id'] = ['in', $cat_ids];//包含所有子系列

//        $art_ids = Db::name('article_ext_cat')->whereIn('cat_id', $cat_ids)->column('art_id');
//        $where['art_id'] = ['in', $art_ids];//扩展分类

        $dataList = $this->currentModel->getDataList($map);
        $this->assign('dataList', $dataList);

        //获取banner
        $banner = $this->currentModel->getBanner('banner', 'AB');
        $this->assign('banner', $banner);

        $this->assign('web', ['title' => '信息中心']);//网站标题
        return $this->fetch();
    }

    /**
     * 详情页
     * @return mixed
     */
    public function detail()
    {
        $param = $this->request->param();
        $id = !empty($param['id']) ? $param['id'] : 0;
        $data = $this->currentModel->getArticleInfo(['art_id'=>$id]);
        $this->assign('data', $data);
        if (empty($data)) {
            return $this->fetch(STATIC_PATH.'/404.html');
        }

        //获取最近文章列表
        $cat_ids = $this->currentModel->getCatIdByCatType(['cat_type'=>205]);//类型：信息中心cat_id 集
        $latestList = $this->currentModel->getLatestNews(['cat_id'=>['in', $cat_ids]]);
        $this->assign('latestList', $latestList);

        $this->assign('web', ['title' => $data['title']]);//网站标题
        return $this->fetch();
    }


}

